﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Atlandiz.Data;

namespace Atlandiz.EnvanterVeZimmetYonetimi
{
    public partial class FormCihazModel : DevExpress.XtraEditors.XtraForm
    {
        //MsSqlAccessLayer SQL = new MsSqlAccessLayer(".\\SQLExpress","TeknoEnva",true);

        public int KayID;

        public FormCihazModel()
        {
            InitializeComponent();
        }


        public void KayitGetir()
        {
            _txtMarkaString.Text = Army.SQL().GetDataCell("Select ChzMarka from CihazMarka where cmID=(Select cmID from CihazModel where cmdID=" + KayID + ")");
            _txtMarkaInt.Text = Army.SQL().GetDataCell("Select cmID from CihazMarka where cmID=(Select cmID from CihazModel where cmdID=" + KayID + ")");
            _txtCihazModelString.Text = Army.SQL().GetDataCell("Select ChzModel from CihazModel where cmdID=" + KayID);

            ////DataTable dt = SQL.GetDataTable("Select ChzMarka,cmID from CihazMarka where cmID=(Select cmID from CihazModel where cmdID=" + KG + ")");
            ////textEdit1.Text = dt.Rows[0][0].ToString();
            ////textEdit2.Text = dt.Rows[0][1].ToString();
            ////textEdit3.Text = SQL.GetDataCell("Select ChzModel from CihazModel where cmdID=" + KG);

        }

        private void CihazModel_Load(object sender, EventArgs e)
        {
            if (KayID != 0)
            {
                KayitGetir();
            }
            
        }


        private void textEdit3_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void textEdit1_EditValueChanged(object sender, EventArgs e)
        {

        }
        public void formuTemizle()
        {
            _txtMarkaString.Text = "";
            _txtMarkaInt.Text = "";
            _txtCihazModelString.Text = "";
            _txtMarkaString.Focus();
        }

        private void _bntSec_Click(object sender, EventArgs e)
        {
            ListeCihazMarka cml = new ListeCihazMarka();
            cml.ForSelection = true;
            cml.ShowDialog();
            if (Army.EventConfirm == true)
            {
                _txtMarkaInt.Text = Army.SecilenID.ToString();
                _txtMarkaString.Text = Army.SQL().GetDataCell("Select ChzMarka from CihazMarka where cmID=" + _txtMarkaInt.Text);
            }
        }

        private void _btnKaydet_Click(object sender, EventArgs e)
        {
            if (KayID == 0)
            {
                if (_txtMarkaString.Text == "")
                {
                    MessageBox.Show("Lütfen, İlgili Markayı Seçiniz...");
                    return;
                }

                if (_txtCihazModelString.Text == "")
                {
                    MessageBox.Show("Lütfen, Modeli giriniz...");
                    return;
                }

                Army.SQL().cmd("Insert CihazModel (ChzModel,cmID) values('" + _txtCihazModelString.Text.ToString().Replace("'", "''") + "','" + _txtMarkaInt.Text + "')");
                formuTemizle();
            }
            else
            {
                if (_txtMarkaString.Text == "")
                {
                    MessageBox.Show("Lütfen, İlgili Markayı Seçiniz...");
                    return;
                }

                if (_txtCihazModelString.Text == "")
                {
                    MessageBox.Show("Lütfen, Modeli giriniz...");
                    return;
                }

                Army.SQL().cmd("Update CihazModel Set ChzModel='" + _txtCihazModelString.Text + "', cmID='" + _txtMarkaInt.Text + "' where cmdID=" + KayID);
                MessageBox.Show("Kayıt {" + KayID + "} Güncellendi.");
                this.Close();
            }
        }

        private void _btnKapat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void _btnFormuTemizle_Click(object sender, EventArgs e)
        {
            formuTemizle();
        }

        private void _btnCihazModelListesi_Click(object sender, EventArgs e)
        {
            ListeCihazModel cmdl = new ListeCihazModel();
            cmdl.ShowDialog();
        }
    }
}